$(function(){
	var count=document.getElementById("count").value;
	var userGrid = $("#transferMassage");
	var i=0;
	//初始化
	userGrid.datagrid({
		url:'student/mymassagelist',
		fit:true,
		border :false,
		fitColumns:true,
		emptyMsg:"<img src='public/images/kkry.png'/>",
		rownumbers:true,
		pagination : true,// 是否显示分页栏
		columns : [ [ {
			field : 'frontEmp',
			title : '移交人',
			align : 'center',
			width : 90,
			formatter: function (value, rec) {
		         return rec.frontEmp.name;
		     }
		}, {
			field : 'student',
			title : '学生',
			align : 'center',
			width : 90,
			formatter: function (value, rec) {
		         return rec.student.name;
		     }
		}, {
			field : 'afterEmp',
			title : '接收人',
			align : 'center',
			width : 90,
			formatter: function (value, rec) {
		         return rec.afterEmp.name;
		     }
		}, {
			field : 'state',
			title : '状态',
			align : 'center',
			width : 90
		} , {
			field : 'reason',
			title : '移交原因',
			align : 'center',
			width : 90
		}, {
			field : 'transferTime',
			title : '移交时间',
			align : 'center',
			width : 90,
			formatter : function(val){
				var newTime = new Date(val);
				var year = newTime.getFullYear();  //获取年
		        var month = newTime.getMonth() + 1;    //获取月
		        var day = newTime.getDate(); //获取日
		        var hours = newTime.getHours(); 
		        var minutes = newTime.getMinutes();
		        var time = year + "-" + month + "-" + day + "" + " " + hours + ":" + minutes;
				return time;
			}
		}, {
			field : 'ac',
			title : '操作',
			width : 100,
			align : 'center',
			formatter:function(value,row,index){
				var bts = [];
				bts.push('<a data-id="'+row.id+'" data-index="'+index+'" class="ctr agree">同意</a>');
				bts.push('<a data-id="'+row.id+'" data-index="'+index+'" class="ctr delete">拒绝</a>');
				return bts.join('');
			}
		} ] ],
	});
	
	var gridPanel = userGrid.datagrid("getPanel");
	gridPanel.on("click", "a.delete", function() {
		// 获取data-xxx绑定的标签属性数据
		var index = this.dataset.index;
		var id = this.dataset.id;
		$.messager.confirm("提示", "您确定要拒绝这次移交?", function(r) {
			// 点击了确定按钮，r返回的结果为true
			if (r) {
				$.get("student/deletemessage/" + id, function(rs) {
					if (rs.success) {
						// 刷新表格
						userGrid.datagrid("reload");
					} else {
						$.message.alert("提示", rs.message);
					}
				});
			}
		});
	}).on("click", "a.agree", function() {
		// 获取data-xxx绑定的标签属性数据
		var index = this.dataset.index;
		var id = this.dataset.id;
		$.messager.confirm("提示", "您确定要同意这次移交?", function(r) {
			// 点击了确定按钮，r返回的结果为true
			if (r) {
				$.get("student/agreemessage/" + id, function(rs) {
					if (rs.success) {
						// 刷新表格
						userGrid.datagrid("reload");
					} else {
						$.message.alert("提示", rs.message);
					}
				});
			}
		});
	});
});